var basePath = "http://localhost:8080/AboutMe";
var roleTable;
var roleModal;
var roleForm;

$(function() {
	roleModal = $('#roleModal');
	roleForm = $('#roleForm');
	loadTable();
});
function loadTable(){
	roleTable = $('#roleTable').bootstrapTable({
		url : basePath + '/admin/roleList',
		idField : 'roleId',
		pagination : true,
		pageSize : 10,
		pageNumber : 1,
		contentType: "application/x-www-form-urlencoded",
		method : 'post',
		dataType : 'json',
		sidePagination: "server",
		toolbar : '#toolbar',
		undefinedText : '',
		clickToSelect : true,
		columns : [ {
			radio : true
		},{
			field : 'roleName',
			title : '角色姓名',
		}]
	});
}

function add(){
	$('#addSave').show();
	$('#editSave').hide();
	roleModal.find('.modal-title').text('新增角色')
	roleModal.modal('show');
}

function del(){
	var rows = roleTable.bootstrapTable('getSelections');
	$.ajax({
		url : basePath + '/admin/delRole',
		type : "POST" ,
		dataType:'json',
		data : {roleId : rows[0].roleId},
		success : function(data){
			roleModal.modal('hide');
			roleTable.bootstrapTable('refresh');
		}
	}); 
}

function save(stat){
	$.ajax({
		url : basePath + '/admin/saveRole',
		type : "POST" ,
		dataType:'json',
		data : roleForm.serialize(),
		success : function(data){
			roleModal.modal('hide');
			roleTable.bootstrapTable('refresh');
		}
	}); 
}